import androidx.compose.foundation.background
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.PointerIcon.Companion.Text
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.himanshoe.kalendar.endlos.DaySelectionMode
import com.himanshoe.kalendar.endlos.Kalendar
import com.himanshoe.kalendar.endlos.KalendarType
import com.himanshoe.kalendar.endlos.model.KalendarEvents
import com.himanshoe.kalendar.endlos.paging.rememberKalendarPagingController
import com.himanshoe.kalendar.endlos.ui.color.KalendarColor
import com.himanshoe.kalendar.endlos.ui.color.KalendarColors
import com.himanshoe.kalendar.endlos.ui.day.KalendarDayKonfig
import com.himanshoe.kalendar.endlos.ui.header.KalendarTextKonfig

/*
*author:guyueyuan
*createTime:2024/11/17
*/

@Composable
fun ScheduleCalendarEndle() {
    Kalendar(
        modifier = Modifier
            .fillMaxSize(),
        showLabel = true,
//        这个开源组件好垃圾
        kalendarType = KalendarType.Vertical,
        pagingController = rememberKalendarPagingController(),
        kalendarHeaderTextKonfig = KalendarTextKonfig(
            kalendarTextColor= Color.Red,
            kalendarTextSize = TextUnit(16.0F, TextUnitType.Sp)
        ),

        events = KalendarEvents(),
        kalendarDayKonfig = KalendarDayKonfig(
            size = 56.dp,
            textSize = 16.sp,
            textColor = Color(0xFF413D4B),
            selectedTextColor = Color.Blue
        ),
        contentPadding = PaddingValues(16.dp),
        monthContentPadding = PaddingValues(8.dp),
        dayContent = { date ->
            Text(
                text = date.dayOfMonth.toString(),
                fontSize = 16.sp,
                color = Color.Black
            )
        },
        headerContent = { month, year ->
            Text(
                text = "${month.name}, $year",
                fontSize = 20.sp,
                fontWeight = FontWeight.Bold,
                color = Color.Black
            )
        },
        daySelectionMode = DaySelectionMode.Range,
        onDayClicked = { date, events ->
            // Handle day click event
            println("Selected day: $date, Events: $events")
        },
        onRangeSelected = { range, events ->
            // Handle range selection event
        },
        onErrorRangeSelected = { error ->
            // Handle range selection error
        }
    )
}

@Preview
@Composable
fun ScheduleCalendarEndlePre() {
    ScheduleCalendarEndle()
}